public class Test4 {
    public static void main(String[] args) {

        try {
            System.out.println("2 + 3 = " + add(2, 3));
            System.out.println("-8 + 10 = " + add(-8, 10));
        } catch(Exception e) {
            System.out.println("异常: " + e);
        } finally {
            System.out.println("end");
        }
    }

    static int add(int n, int m) throws MyException{
        if (n < 0 || m < 0) {
            throw new MyException();
        }
        return m + n;
    }
}

class MyException extends Exception {
//    public MyException() {
//
//    }

    static final long serialVersionUID = 123456L;

    public  MyException() {
        super("数据为负数");
    }
}